<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>9.函数防抖</title>
		<script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
	</head>
	<body>
		<input id="input" type="text" placeholder="请输入关键字">
		
		<script type="text/javascript" >
			//获取元素
			const input = document.getElementById('input')
			
			//靠定时器实现防抖（笨、不好看）
			/*let timeId
			input.onkeyup = (event)=>{
				if(timeId) clearTimeout(timeId)
				timeId = setTimeout(()=>{
					console.log('发送ajax请求，携带的关键字为：',event.target.value)
				},200)
			} */
			
			//靠lodash实现
			input.onkeyup = _.debounce((event)=>{
				console.log('发送ajax请求，携带的关键字为：',event.target.value)
			},1000)


		</script>
	</body>
</html>